home *** CD-ROM | disk | FTP | other *** search
/ Micromanía 90 / CDMM_90_1.ISO / Cycling Manager 2 / CyclingManager2Demo.exe / Disk1 / data1.cab / Game / DataCM2 / scripts / elements / tabcontrol.cnh < prev    next >
Encoding:
Text File  |  2002-05-10  |  7.6 KB  |  357 lines

  1. // Tab control
  2.  
  3.  
  4. // -------------------------------------------------------------
  5. // Constructors
  6. // -------------------------------------------------------------
  7. func Gui_Component NewTabControl();
  8. // Message
  9. message BackgroundTab(i32x _iTabId);
  10. message ShowTab(i32x _iTabId);
  11. message ShowTabOver(i32x _iTabId);
  12. message HideTab();
  13. message NextTab();
  14. message PreviousTab();
  15. message AddTab(Gui_Component _poTab);
  16. message SetOnBackground(i32x _iTabId);
  17. message SetOnForeground();
  18. message ToggleOk();
  19. // -------------------------------------------------------------
  20. // -------------------------------------------------------------
  21.  
  22.  
  23.  
  24. // Data class
  25. class Gui_dtTabControl
  26. {
  27.     var i32x iBackgroundId; // Current displayed background tab Id
  28.     var i32x iTabId; // Current displayed tab Id
  29.     var i32x iNumTab; // Tab number
  30. };
  31.  
  32. // forward declaration
  33.  
  34. func void TabControl_ShowTab(i32x _iTabId);
  35. func void TabControl_ShowTabOver(i32x _iTabId);
  36. func void TabControl_HideTab();
  37. func void TabControl_ToggleOk();
  38. func void TabControl_NextTab();
  39. func void TabControl_PreviousTab();
  40. func void TabControl_BackgroundTab(i32x _iTabId);
  41. func void TabControl_AddTab(Gui_Component _poTab);
  42. func void TabControl_WindowUpdate();
  43.  
  44. // Message handling interface
  45. interface Gui_iTabControl
  46. {
  47.     TabControl_ShowTab ShowTab;
  48.     TabControl_ShowTabOver ShowTabOver;
  49.     TabControl_NextTab NextTab;
  50.     TabControl_PreviousTab PreviousTab;
  51.     TabControl_AddTab AddTab;
  52.     TabControl_HideTab HideTab;
  53.     TabControl_BackgroundTab BackgroundTab;
  54.     TabControl_ToggleOk ToggleOk;
  55.     TabControl_WindowUpdate WindowUpdate;
  56. }
  57.  
  58. func Gui_Component NewTabControl()
  59. {
  60.     var Gui_Component ptabcontrol;
  61.     var Gui_dtTabControl pdtTabcontrol;
  62.  
  63.     // Create table object
  64.     ptabcontrol = NewObject(Gui_iTabControl);
  65.     pdtTabcontrol = new Gui_dtTabControl;
  66.     SetData(ptabcontrol,pdtTabcontrol);
  67.  
  68.     // Fill data
  69.     pdtTabcontrol.iNumTab = 0;
  70.     pdtTabcontrol.iTabId = -1;
  71.     pdtTabcontrol.iBackgroundId = -1;
  72.  
  73.     // Stretch tab control
  74. //    Clip(ptabcontrol);
  75.     Transparent(ptabcontrol);
  76.  
  77.     return ptabcontrol;
  78. }
  79.  
  80. func void TabControl_ToggleOk()
  81. {
  82.     var Gui_Component ptabcontrol,ptab,pparent;
  83.     var Gui_dtTabControl pdtTab;
  84.     var i32x iWidth,iHeight;
  85.  
  86.     // Retrieve table pointer
  87.     ptabcontrol = GetThis();
  88.  
  89.     // Retrieve data pointer
  90.     pdtTab = GetData(ptabcontrol);
  91.     ptab = GetComponent(ptabcontrol,pdtTab.iTabId);
  92.     if(ptab)
  93.     {
  94.         iWidth = SizeX(ptab);
  95.         iHeight = SizeY(ptab);
  96.  
  97.         // Show table
  98.         ptab<<Show();
  99.  
  100.         // Make appear in foreground
  101.         GoToForeground(ptabcontrol,pdtTab.iTabId);
  102.  
  103.         // Stretch tab control to fit content
  104.         StretchTo(ptabcontrol,iWidth,iHeight);
  105.  
  106.         // Send window content update
  107.         pparent = GetParent(ptabcontrol);    
  108.         if(pparent)
  109.             pparent<<WindowUpdate();
  110.     }
  111. }
  112.  
  113. func void TabControl_ShowTabOver(i32x _iTabId)
  114. {
  115.     var Gui_Component ptabcontrol,ptab,pparent;
  116.     var Gui_dtTabControl pdtTab;
  117.     var i32x iWidth,iHeight;
  118.  
  119.     // Retrieve table pointer
  120.     ptabcontrol = GetThis();
  121.  
  122.     // Retrieve data pointer
  123.     pdtTab = GetData(ptabcontrol);
  124.  
  125.     ptab = GetComponent(ptabcontrol,_iTabId);
  126.     if(ptab)
  127.     {
  128.         iWidth = SizeX(ptab);
  129.         iHeight = SizeY(ptab);
  130.         // Display new table over the other
  131.         ptab<<Show();
  132.  
  133.         // Make appear in foreground
  134.         GoToForeground(ptabcontrol,_iTabId);
  135.  
  136.         // Stretch tab control to fit content
  137.         StretchTo(ptabcontrol,iWidth,iHeight);
  138.         // Send window content update
  139.         pparent = GetParent(ptabcontrol);    
  140.         
  141.         if(pparent)
  142.             pparent<<WindowUpdate();
  143.     }
  144. }
  145.  
  146. func void TabControl_WindowUpdate()
  147. {
  148.     var Gui_Component ptabcontrol,ptab,pparent;
  149.     var Gui_dtTabControl pdtTab;
  150.     var i32x iWidth,iHeight;
  151.  
  152.     // Retrieve table pointer
  153.     ptabcontrol = GetThis();
  154.  
  155.     // Retrieve data pointer
  156.     pdtTab = GetData(ptabcontrol);
  157.     ptab = GetComponent(ptabcontrol,pdtTab.iTabId);
  158.         
  159.     if(ptab)
  160.     {
  161.         iWidth = SizeX(ptab);
  162.         iHeight = SizeY(ptab);
  163.         
  164.         //println("TabControlWindowUpdate");
  165.         //println(itoa(iWidth));
  166.         //println(itoa(iHeight));
  167.         
  168.         // Stretch tab control to fit content
  169.         StretchTo(ptabcontrol,iWidth,iHeight);
  170.         // Send window content update
  171.         pparent = GetParent(ptabcontrol);    
  172.         if(pparent)
  173.             pparent<<WindowUpdate();
  174.     }
  175. }
  176.  
  177. func void TabControl_ShowTab(i32x _iTabId)
  178. {
  179.     var Gui_Component ptabcontrol,ptab,pparent;
  180.     var Gui_dtTabControl pdtTab;
  181.     var i32x iWidth,iHeight;
  182.     var boolx bWaitForToggle;
  183.  
  184.     bWaitForToggle = false;
  185.     // Retrieve table pointer
  186.     ptabcontrol = GetThis();
  187.  
  188.     // Retrieve data pointer
  189.     pdtTab = GetData(ptabcontrol);
  190.  
  191.     if(_iTabId != pdtTab.iTabId)
  192.     {
  193.         // Switch tab
  194.         if(pdtTab.iTabId != -1)
  195.         {
  196.             ptab = GetComponent(ptabcontrol,pdtTab.iTabId);
  197.             if(ptab)
  198.             {
  199.                 if(pdtTab.iTabId != pdtTab.iBackgroundId)
  200.                 {
  201.                     ptab<<Hide();
  202.                 }
  203.                 else
  204.                 {
  205.                     bWaitForToggle = true;
  206.                 }
  207.                 // Inform go back
  208.                 //ptab<<Disable();
  209.                 ptab<<SetOnBackground(_iTabId);
  210.             }
  211.         }
  212.         pdtTab.iTabId = _iTabId;
  213.         if(bWaitForToggle == false)
  214.         {
  215.             ptab = GetComponent(ptabcontrol,pdtTab.iTabId);
  216.             if(ptab)
  217.             {
  218.                 iWidth = SizeX(ptab);
  219.                 iHeight = SizeY(ptab);
  220.                 // Display new table
  221.                 if(pdtTab.iTabId != pdtTab.iBackgroundId)
  222.                 {
  223.                     ptab<<Show();
  224.                 }
  225.                 // Inform go to foreground
  226.                 //ptab<<Enable();
  227.                 ptab<<SetOnForeground();
  228.  
  229.                 // Make appear in foreground
  230.                 GoToForeground(ptabcontrol,pdtTab.iTabId);
  231.  
  232.                 // Stretch tab control to fit content
  233.                 StretchTo(ptabcontrol,iWidth,iHeight);
  234.                 // Send window content update
  235.                 pparent = GetParent(ptabcontrol);    
  236.                 if(pparent)
  237.                     pparent<<WindowUpdate();
  238.             }
  239.         }
  240.     }
  241. }
  242.  
  243. func void TabControl_BackgroundTab(i32x _iTabId)
  244. {
  245.     var Gui_Component ptabcontrol,ptab;
  246.     var Gui_dtTabControl pdtTab;
  247.  
  248.     // Retrieve table pointer
  249.     ptabcontrol = GetThis();
  250.  
  251.     // Retrieve data pointer
  252.     pdtTab = GetData(ptabcontrol);
  253.  
  254.     if(pdtTab.iBackgroundId != -1)
  255.     {
  256.         // Switch tab
  257.         ptab = GetComponent(ptabcontrol,pdtTab.iBackgroundId);
  258.         if(ptab)
  259.         {
  260.             ptab<<Hide();
  261.         }
  262.     }
  263.  
  264.     if(pdtTab.iBackgroundId != _iTabId)
  265.     {
  266.         pdtTab.iBackgroundId = _iTabId;
  267.  
  268.         if(_iTabId!=-1)
  269.         {
  270.             ptab = GetComponent(ptabcontrol,pdtTab.iBackgroundId);
  271.             if(ptab)
  272.             {
  273.                 ptab<<Show();
  274.             }
  275.         }
  276.     }
  277. }
  278.  
  279. func void TabControl_HideTab()
  280. {
  281.     var Gui_Component ptabcontrol,ptab,pparent;
  282.     var Gui_dtTabControl pdtTab;
  283.     var i32x iWidth,iHeight;
  284.  
  285.     // Retrieve table pointer
  286.     ptabcontrol = GetThis();
  287.  
  288.     // Retrieve data pointer
  289.     pdtTab = GetData(ptabcontrol);
  290.  
  291.     // Switch tab
  292.     ptab = GetComponent(ptabcontrol,pdtTab.iTabId);
  293.     if(ptab)
  294.     {
  295.         ptab<<Hide();
  296.     }
  297.     pdtTab.iTabId = -1;
  298.  
  299.     // Send window content update
  300.     pparent = GetParent(ptabcontrol);    
  301.     if(pparent)
  302.         pparent<<WindowUpdate();
  303. }
  304.  
  305. func void TabControl_NextTab()
  306. {
  307.     var Gui_Component ptabcontrol;
  308.     var Gui_dtTabControl pdtTab;
  309.  
  310.     // Retrieve table pointer
  311.     ptabcontrol = GetThis();
  312.  
  313.     // Retrieve data pointer
  314.     pdtTab = GetData(ptabcontrol);
  315.  
  316.     if(pdtTab.iTabId < pdtTab.iNumTab)
  317.     {
  318.         TabControl_ShowTab(pdtTab.iTabId+1);
  319.     }
  320. }
  321. func void TabControl_PreviousTab()
  322. {
  323.     var Gui_Component ptabcontrol,ptab;
  324.     var Gui_dtTabControl pdtTab;
  325.  
  326.     // Retrieve table pointer
  327.     ptabcontrol = GetThis();
  328.  
  329.     // Retrieve data pointer
  330.     pdtTab = GetData(ptabcontrol);
  331.  
  332.     if(pdtTab.iTabId > 0)
  333.     {
  334.         TabControl_ShowTab(pdtTab.iTabId-1);
  335.     }
  336. }
  337. func void TabControl_AddTab(Gui_Component _poTab)
  338. {
  339.     var Gui_Component ptab;
  340.     var Gui_dtTabControl pdtTab;
  341.  
  342.     // Retrieve table pointer
  343.     ptab = GetThis();
  344.  
  345.     // Retrieve data pointer
  346.     pdtTab = GetData(ptab);
  347.  
  348.     // Mount tab on tabcontrol
  349.     MountComponent(ptab,_poTab);
  350.  
  351.     // Increment tab number
  352.     pdtTab.iNumTab = pdtTab.iNumTab + 1;
  353.  
  354.     // Hide added tab
  355.     _poTab<<Hide();
  356. }
  357.